# -*- coding: utf-8 -*-
"""
Created on Fri Jul 27 19:53:15 2018

@author: Zhang Yafei
"""

import datetime

1.获取当前datetime
datetime.datetime.now().year
datetime.datetime.now().month
datetime.datetime.now().day

2.获取当前date
datetime.date.today() = datetime.datetime.now().date()

3.获取明天/前N天
datetime.date.today() + datetime.timedelta(days=1)
datetime.datetime.now() - datetime.timedelta(seconds=3)

4.获取两个datetime的时间差
datetime.datetime(2018,1,13,12,0,0) - datetime.datetime.now()

5.关系转换
datetime->string
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

string->datetime
datetime.datetime.strptime('2018-12-21 12:12:12','%Y-%m-%d %H:%M:%S')

datetime->timestamp
now = datetime.datetime.now()
timestamp = time.mktime(now.timetuple())
timestamp

timestamp->datetime
datetime.datetime.fromtimestamp(1232323232.32)

datetime->date
datetime.datetime.now().date()
today = datetime.date.today()
datetime.datetime.combine(today,datetime.time())








l





















